from appium.webdriver.common.appiumby import AppiumBy as By
from pages.base_page import BasePage

# 定位器
my_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("我")')
recipe_locator = (By.XPATH, '//android.widget.TextView[@text="菜谱 0"]')
text_01_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/profile_empty_recipe_header_create_recipe_btn")')
photo_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_photo_picker_photo").instance(1)')
t_recipe_name_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/et_recipe_name")')
et_recipe_desc_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/et_recipe_desc")')
text_02_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/et_ing")')
et_amount_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/et_amount")')
tv_step_hint_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/tv_step_hint").instance(0)')
photo_02_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_photo_picker_photo").instance(3)')
tv_publish_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/tv_publish")')
success_textview_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/model_create_success_textview")')
navigation_right_btn_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/navigation_right_btn")')
item_img_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_img")')
description_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().description("更多操作")')
item_share_icon_locator_11 = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_share_icon").instance(11)')
item_share_icon_locator_05 = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_share_icon").instance(5)')
item_share_icon_locator_06 = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_share_icon").instance(6)')
item_share_icon_locator_07 = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_share_icon").instance(7)')
item_share_icon_locator_08 = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_share_icon").instance(8)')
item_share_icon_locator_09 = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_share_icon").instance(9)')
item_share_icon_locator_10 = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_share_icon").instance(10)')
button1_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("android:id/button1")')
# 存草稿箱
tv_save_draft_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/tv_save_draft")')
draft_name_locator = (By.ID, 'com.xiachufang:id/draft_name')


class MyRecipePage(BasePage):

    def click_my(self):
        """
        点击我
        :return:
        """
        self.find_element(my_locator).click()

    def click_recipe(self):
        """
        点击菜谱
        :return:
        """
        self.find_element(recipe_locator).click()

    def click_text_01(self):
        """
        点击发布菜谱
        :return:
        """
        self.find_element(text_01_locator).click()

    def click_photo(self):
        """
        点击图片
        :return:
        """
        self.find_element(photo_locator).click()

    def input_recipe_name(self):
        """
        输入菜谱名称
        :return:
        """
        self.find_element(t_recipe_name_locator).send_keys("红枣")

    def input_recipe_desc(self):
        """
        输入菜谱描述
        :return:
        """
        self.find_element(et_recipe_desc_locator).send_keys("红枣")

    def input_text_02(self):
        """
        点击食材用料
        :return:
        """
        self.find_element(text_02_locator).send_keys("红枣")

    def input_amount(self):
        """
        输入食材数量
        :return:
        """
        self.find_element(et_amount_locator).send_keys("1个")

    def click_tv_step_hint(self):
        """
        点击添加步骤
        :return:
        """
        self.find_element(tv_step_hint_locator).click()

    def click_photo_02(self):
        """
        选择步骤图片
        :return:
        """
        self.find_element(photo_02_locator).click()

    def click_tv_publish(self):
        """
        点击发布
        :return:
        """
        self.find_element(tv_publish_locator).click()

    def get_success_textview(self):
        """
        获取发布成功文案
        :return:
        """
        return self.find_element(success_textview_locator).text

    def click_navigation_right_btn(self):
        """
        点击关闭
        :return:
        """
        self.find_element(navigation_right_btn_locator).click()

    def click_item_img(self):
        """
        点击菜谱图片
        :return:
        """
        self.find_element(item_img_locator).click()

    def click_description(self):
        """
        点击更多操作
        :return:
        """
        self.find_element(description_locator).click()

    def click_item_share_icon_11(self):
        """
        点击删除
        :return:
        """
        self.find_element(item_share_icon_locator_11).click()

    def click_item_share_icon_05(self):
        """
        点击烹饪模式
        :return:
        """
        self.find_element(item_share_icon_locator_05).click()

    def click_item_share_icon_06(self):
        """
        点击菜篮子
        :return:
        """
        self.find_element(item_share_icon_locator_06).click()

    def click_item_share_icon_07(self):
        """
        点击备注
        :return:
        """
        self.find_element(item_share_icon_locator_07).click()

    def click_item_share_icon_08(self):
        """
        点击加入计划
        :return:
        """
        self.find_element(item_share_icon_locator_08).click()

    def click_item_share_icon_09(self):
        """
        点击拷贝链接
        :return:
        """
        self.find_element(item_share_icon_locator_09).click()

    def click_item_share_icon_10(self):
        """
        点击编辑
        :return:
        """
        self.find_element(item_share_icon_locator_10).click()

    def click_tv_save_draft(self):
        """
        点击存草稿箱
        :return:
        """
        self.find_element(tv_save_draft_locator).click()

    def get_draft_name(self):
        """
        获取草稿箱名称
        :return:
        """
        return self.find_element(draft_name_locator).text

    def click_button1(self):
        """
        点击确定
        :return:
        """
        self.find_element(button1_locator).click()